﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/Admin.master" AutoEventWireup="true"
    Inherits="Admin_ConstituentManagement" CodeBehind="ConstituentManagement.aspx.cs"
    ValidateRequest="false" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajt" %>
<asp:Content ID="Content1" ContentPlaceHolderID="cphHead" runat="Server">
    <script src="../Scripts/jquery.maskedinput-1.2.2.js" type="text/javascript"></script>
    
    <script type="text/javascript" language="javascript">
        $(document).ready(function () {
            $("#<%=txtPhone.ClientID%>").mask("(999) 999-9999");
            $("#<%=txtZip.ClientID%>").mask("99999-9999");

            $("#<%=txtConstituentSearch.ClientID %>").keyup(function (e) {
                var textValue = $(this).val();
                __doPostBack('<%= updatePanelConstituents.ClientID %>', textValue);
            });

            $("#<%=ddlPageSize.ClientID %>").change(function (e) {
                __doPostBack('<%= updatePanelConstituents.ClientID %>', '');
            });
        });

        function ChangeVisibility() {
            var checked = $("#<%=chkIsOrganization.ClientID%>").prop("checked");
            var orgVis, constitVis;

            if (checked == false) {
                orgVis = "none";
                constitVis = "inline";
            } else {
                orgVis = "inline";
                constitVis = "none";
            }

            pnlOrganization.style.display = orgVis;
            pnlConstituent.style.display = constitVis;
        }
    </script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="cphTitle" runat="Server">
    Customers
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cphBody" runat="Server">
    <asp:ScriptManager ID="scriptManager1" runat="server" />
    <asp:LinkButton ID="btnNewConstituent" Text="Create a customer" OnClick="btnNewConstituent_Click"
        runat="server" />
    <br />
    <br />
    <table align="center">
        <tr>
            <td align="left">
                <asp:DropDownList ID="ddlPageSize" runat="server">
                    <asp:ListItem Text="10" Value="10" />
                    <asp:ListItem Text="25" Value="25" />
                    <asp:ListItem Text="50" Value="50" />
                    <asp:ListItem Text="100" Value="100" />
                </asp:DropDownList>
            </td>
            <td align="right">
                <asp:TextBox ID="txtConstituentSearch" runat="server" MaxLength="50" />
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <asp:UpdatePanel ID="updatePanelConstituents" runat="server">
                    <ContentTemplate>
                        <asp:GridView ID="grvConstituents" runat="server" AutoGenerateColumns="false" PagerSettings-NextPageText="Next"
                            PagerSettings-PreviousPageText="Previous" PagerSettings-Mode="NextPrevious" AllowPaging="true" 
                            OnPageIndexChanging="grvConstituents_PageIndexChanging" AllowSorting="true"
                            OnSorting="grvConstituents_OnSorting" Width="700px" PagerSettings-Position="Bottom"
                            EmptyDataText="No customers that match that criteria.">
                            <Columns>                                
                                <asp:TemplateField SortExpression="ORGANIZATION" HeaderText="Customer">
                                    <ItemTemplate>
                                        <asp:LinkButton ID="linkButton1" runat="server" Text='<%# Eval("ORGANIZATION") %>' OnClick="linkButton1_OnClick" CommandArgument='<%# Eval("ID") %>' />
                                    </ItemTemplate>
                                </asp:TemplateField>                                                               
                                <asp:TemplateField HeaderText="Contact" SortExpression="PRIMARYCONTACT">
                                    <ItemTemplate>
                                        <%# Eval("PRIMARYCONTACT") %>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Phone" SortExpression="PHONENUMBER">
                                    <ItemTemplate>
                                        <%# Eval("PHONENUMBER") %>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Email" SortExpression="EMAILADDRESS">
                                    <ItemTemplate>
                                        <%# Eval("EMAILADDRESS") %>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>                        
                    </ContentTemplate>
                </asp:UpdatePanel>
            </td>
        </tr>
    </table>
    <ajt:ModalPopupExtender ID="modalNewConstituent" runat="server" CancelControlID="btnCancel"
        TargetControlID="btnNewConstituent" PopupControlID="pnlNewGuest" PopupDragHandleControlID="PopupHeader"
        Drag="true" BehaviorID="ShowModal" BackgroundCssClass="modalBackground">
    </ajt:ModalPopupExtender>
    <asp:Panel ID="pnlNewGuest" runat="server">
        <div id="modal">
            <div class="modal">
                <table width="600" border="0">
                    <tr>
                        <td align="center" colspan="2">
                            <p>
                                Create a customer</p>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <asp:Label ID="lblConstituentError" runat="server" CssClass="errorLabel" />
                        </td>
                    </tr>
                    <tr>
                        <td align="left" width="300" valign="top">
                            <table>
                                <tr>
                                    <td colspan="2">
                                        <asp:CheckBox ID="chkIsOrganization" runat="server" Text="Is an organization?" Checked="true"
                                            onclick="javascript:ChangeVisibility();" />
                                        <div id="pnlOrganization">
                                            <table>
                                                <tr>
                                                    <td>
                                                        Name:
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="txtOrganizationName" runat="server" MaxLength="100" />
                                                    </td>
                                                </tr>
                                            </table>
                                        </div>
                                        <div id="pnlConstituent" style="display: none;">
                                            <table>
                                                <tr>
                                                    <td>
                                                        First name:
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="txtFirstName" runat="server" MaxLength="100" />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        Last name:
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="txtLastName" runat="server" MaxLength="100" />
                                                    </td>
                                                </tr>
                                            </table>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2">
                                        <hr />
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        Type:
                                    </td>
                                    <td>
                                        <asp:DropDownList ID="ddlPhoneType" runat="server" />
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        Phone:
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtPhone" runat="server" MaxLength="20" Columns="11" />
                                        ext.
                                        <asp:TextBox ID="txtExtension" runat="server" MaxLength="6" Columns="3" />
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2">
                                        <hr />
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        Type:
                                    </td>
                                    <td>
                                        <asp:DropDownList ID="ddlEmailType" runat="server" />
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        Email:
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtEmail" runat="server" MaxLength="100" />
                                    </td>
                                </tr>
                            </table>
                        </td>
                        <td align="left" width="300" valign="top">
                            <table>
                                <tr>
                                    <td>
                                        Type:
                                    </td>
                                    <td>
                                        <asp:DropDownList ID="ddlAddressType" runat="server" />
                                    </td>
                                </tr>
                                <tr>
                                    <td valign="top">
                                        Address:
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtAddress" runat="server" TextMode="MultiLine" MaxLength="1000" />
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        City:
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtCity" runat="server" MaxLength="50" />
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        State:
                                    </td>
                                    <td>
                                        <asp:DropDownList ID="ddlState" runat="server" />
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        Zip code:
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtZip" runat="server" MaxLength="12" Columns="8" />
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        Country:
                                    </td>
                                    <td>
                                        <asp:DropDownList ID="ddlCountry" runat="server" />
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2">
                                        <hr />
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2">
                                        <asp:CheckBox ID="chkSales" runat="server" Text="Sales customer" />
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2">
                                        <asp:CheckBox ID="chkService" runat="server" Text="Service customer" />
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <br />
                        </td>
                    </tr>
                    <tr>
                        <td align="left">
                            <asp:Button ID="btnCancel" runat="server" Text="Cancel" />
                        </td>
                        <td align="right">
                            <asp:Button ID="btnSubmit" runat="server" Text="Create" CausesValidation="false"
                                OnClick="btnSubmit_Click" OnClientClick="showModal();" />
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </asp:Panel>
</asp:Content>
